package fm.dongman.animefm.view.widget;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.StyleRes;
import android.view.View;
import android.widget.Button;
import android.widget.RatingBar;

import fm.dongman.animefm.R;

/**
 * Created by alex on 2017/10/17.
 * @description 动漫详情页 动漫评分dialog
 */

public class AnimeDetailsRatingDialog extends Dialog {

    private AnimeDetailsRatingDialog(@NonNull Context context, @StyleRes int themeResId) {
        super(context, themeResId);
    }

    public static class Builder{
        private Context mContext;
        private OnRatingCommitListener mOnRatingCommitListener;
        private AnimeDetailsRatingDialog mDialog;

        public Builder(Context context){
            mContext=context;
        }

        public Builder setOnRatingCommitListenr(OnRatingCommitListener listenr){
            mOnRatingCommitListener=listenr;
            return this;
        }


        public AnimeDetailsRatingDialog build(){
            mDialog=new AnimeDetailsRatingDialog(mContext,R.style.CustomDialog);
            View layoutView=View.inflate(mContext, R.layout.dialog_anime_details_rating,null);
            mDialog.setContentView(layoutView);
            Button btnCommit= (Button) layoutView.findViewById(R.id.mBtnAnimeDetailsRatingDialogCommit);
            Button btnCancel= (Button) layoutView.findViewById(R.id.mBtnAnimeDetailsRatingDialogCancel);

            btnCancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mDialog.dismiss();
                }
            });

            btnCommit.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    if (mOnRatingCommitListener==null)
                        return;

                    RatingBar mRbStory= (RatingBar) mDialog.findViewById(R.id.mRbDialogStory);
                    RatingBar mRbPaint= (RatingBar) mDialog.findViewById(R.id.mRbDialogPaint);
                    RatingBar mRbMusic= (RatingBar) mDialog.findViewById(R.id.mRbDialogMusic);
                    RatingBar mRbPeople= (RatingBar) mDialog.findViewById(R.id.mRbDialogPeople);

                    mOnRatingCommitListener.onCommit(mDialog,mRbStory.getRating(),mRbPaint.getRating(),mRbMusic.getRating(),mRbPeople.getRating());
                }
            });
            return mDialog;
        }

        public interface OnRatingCommitListener{
            void onCommit(Dialog dialog,float storyScore,float paintScore,float musicScore,float peopleScore);
        }
    }
}
